<%@ page import="java.sql.ResultSet" %>

<%@ include file="connect.jsp" %>
<%--
  Created by IntelliJ IDEA.
  User: Mery
  Date: 10/25/12
  Time: 11:03 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<html>
<head>
    <title></title>
    <link href="style.css" rel="stylesheet"/>
    <script type="text/javascript" language="javascript">
        function validasi() {
            var paragraf = document.getElementById("paragraf").value;

            if (paragraf == null || paragraf == "") {
                err.innerHTML = "Please insert the paragraf!";
                return false;
            }
            else {
                return true;
            }
        }
        function confirmation() {
            var answer = confirm("Are you sure to delete this material?")
            if (answer) {
                window.location = "/doDeletelearn.jsp";
            }
            else {

            }
        }
    </script>

</head>
<body>
<table id="bg" cellspacing="0">
    <tr id="header">

        <td class="link">
            <%@ include file="header.jsp" %>
        </td>
    </tr>
    <tr id="menu">
        <td>
            <%@ include file="menu.jsp" %>
        </td>
    </tr>
    <tr id="content">
        <td class="link" valign="top" style="padding-left: 20px">
            <table>
                <tr id="title">
                    <td>Learn >> Add New Material</td>
                </tr>
            </table>
            <table>
                <form action="doAddMaterial.jsp" method="post" onsubmit="return validasi()">
                    <tr id="word1">
                        <%
                            String idkat = request.getParameter("category");
                            ResultSet rs = stat.executeQuery("select * from Learn a, categories b where a.categoryID = b.categoryID and b.categoryName = '" + idkat + "' order by learnname desc LIMIT 1");
                            String namachap = "";


                            if (rs.next()) {
                                Integer start = rs.getString("learnname").indexOf("chapter");
                                namachap = rs.getString("learnname").substring(0, start + 7);
                                int chap = Integer.parseInt(rs.getString("learnname").substring(start + 7)) + 1;
                                namachap = namachap + chap;
                            } else {
                                namachap = idkat + "_chapter1";
                            }
                            conn.close();
                        %>
                        <td>Learn Name</td>
                        <td>:</td>
                        <td><input style="font-size: 12pt;" type="text" readonly="readonly" name="namalearn"
                                   id="namalearn"
                                   value="<%=namachap%>"></td>
                        <input type="hidden" name="kategori" value="<%=idkat%>">

                    </tr>
                    <tr id="parastyle">
                        <td>Paragraph</td>
                        <td>:</td>
                        <td><textarea name="paragraf" id="paragraf"></textarea></td>
                    </tr>
                    <tr id="warning">
                        <td colspan="3">
                            <div id="err">
                            </div>
                        </td>
                    </tr>
                    <tr align="right">
                        <td colspan="3">
                            <div class="btn-fld">
                                <a href="learn.jsp"><button type="button">Cancel</button></a>
                                <button type="submit">Save</button>

                            </div>
                        </td>
                    </tr>
                </form>
            </table>

        </td>
    </tr>

</table>
</body>
</html>